package com.tlsy.commerce.model;

import com.tlsy.commerce.model.converter.StatusConverter;
import com.tlsy.commerce.model.converter.UserTypeConverter;
import com.tlsy.commerce.model_enum.StatusEnum;
import com.tlsy.commerce.model_enum.UserTypeEnum;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

/**
 * 用户实体
 * @author Tlsy
 * @version commerce 0.0.1
 * @date 2017/4/13  14:12
 */
@Entity
@Table(name = "user")
@Getter
@Setter
public  class User extends IdEntity {
    private static final long serialVersionUID = -6814378561461640352L;


    @Column(name = "phone")
    private String phone;
    @Column(name = "email")
    private String email;
    @Column(name = "address")
    private String address;
    @Column(name = "password")
    private String password;
    @Column(name = "gender")
    private String gender;


    @Column(name = "user_status")
    @Convert(converter = StatusConverter.class)
    private StatusEnum status;


    @Column(name = "user_type")
    @Convert(converter = UserTypeConverter.class)
    private UserTypeEnum type;


    @ManyToMany(cascade = CascadeType.DETACH)
    @JoinTable(name = "user_2_role", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
    private List<Role> roles;

}
